<?php

namespace Matrix\Controller;

class OrderController extends CommonController {
	public function __construct() {
		parent::__construct ();
		parent::__config ( array (
				'model_name' => 'Order' 
		) );
	}
	public function index() {
		parent::__config ( array (
				'fuzzy'=>'consignee,phone,order_by,order_adress',
				'between_time'=>'send_time',
				'statistics'=>array('total_price','carriage','other_fee'),//需要统计求和字段
		) );
		$table = I ( 'table' );
		if (! $table == null && ! empty ( $table )) {
			parent::__config ( array (
					'display' => 'table',
					'display_parms' => array (
							'table' => 1 
					) 
			) );
		}
		parent::index ();
		
	}
	
	// 审核通过
	
	function add() {
		parent::add ();
	}
	function insert() {
		parent::__config ( array (
				'display' => 'index' 
		) );
		$data['order_sn']=date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
		$data['order_adress']=$_POST['order_adress'];
		$data['consignee']=$_POST['consignee'];
		$data['phone']=$_POST['phone'];
		$data['num']=$_POST['num'];
		$data['remark']=$_POST['remark'];
		$data['order_by']=$_POST['order_by'];
		$data['total_price']=$_POST['num']*78;
		$data['created']=time();
		$orderModel = D("Order");
		$orderModel->add($data);
		$this->redirect('Order/index');
		
	}
	function foreverdelete() {
		parent::__config ( array (
				'display' => 'index?table=1' 
		) );
		parent::foreverdelete ();
	}
	function edit() {
		parent::edit();
		// parent::edit ();
	}
	function update() {
		parent::__config ( array (
				'display' => 'index' 
		) );
		$data['order_id']=$_POST['order_id'];
		$data['order_adress']=$_POST['order_adress'];
		$data['consignee']=$_POST['consignee'];
		$data['phone']=$_POST['phone'];
		$data['num']=$_POST['num'];
		$data['remark']=$_POST['remark'];
		$data['consigner']=$_POST['consigner'];
		$data['c_phone']=$_POST['c_phone'];
		$data['express_num']=$_POST['express_num'];
		$data['express_name']=$_POST['express_name'];
		$data['price']=$_POST['price'];
		$data['total_price']=$_POST['num']*$_POST['price'];
		$data['carriage']=$_POST['carriage'];
		if($_POST['send_time']){
			$data['send_time']=strtotime($_POST['send_time']);
		}
		$data['order_by']=$_POST['order_by'];
		$data['other_fee']=$_POST['other_fee'];
		$orderModel = D("Order");
		$orderModel->save($data);
		$this->redirect('Order/index');
	}
	function logout() {
		session ( "bm_ouradmin", null );
		session ( 'order', null );
		$this->redirect ( 'Home/Index/index' );
	}
	function bean() {
		parent::bean ();
	}
	function sort() {
		parent::sort ();
	}
	function excelImport() {
	}
	function excelOutput() {
	}
}